<?php

/**
 * Contains error handler.
 *
 * LICENSE: MIT
 *
 * @author Peter Pippinger
 * @category PP
 * @package PP_Error
 * @copyright Copyright (c) 2015 Peter Pippinger
 * @license http://opensource.org/licenses/MIT
 * @version 1.1.0
 * @since Class exists since release 1.0.0
 */

// Do not show or log errors the "normal" way.
error_reporting(0);
ini_set("display_errors", "off");

/**
 * Checks for fatal errors.
 */
function check_for_fatal()
{
	$sid = session_id();
	$error = error_get_last();
	if ($error["type"] == E_ERROR) {
		Log::error(print_r($error, true));
		file_put_contents(ROOT_PATH . "\\tmp\\$sid.err", serialize($error));
		echo "<script>" . "window.open('" . ROOT_URL . "/lib/error/handlerOutput.php', 'errorHandler', 'width=450,height=250');" . "</script>";
	} else {
		Log::info("Request end");
	}
}

// Register check for fatal errors function.
register_shutdown_function("check_for_fatal");
